package cn.xshi.job.web;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.xshi.job.form.JobLogForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.xshi.common.annotation.Auth;
import cn.xshi.common.base.BaseAction;
import cn.xshi.common.base.BasePage;
import cn.xshi.common.base.BaseResult;
import cn.xshi.common.util.StringUtil;
import cn.xshi.job.model.JobLog;
import cn.xshi.job.service.JobLogService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
/**
 * @Desc 调度器日志
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@RestController
@RequestMapping("/jobLog")
@Api(value = "调度器日志API",tags = "调度器日志API",description = "调度器日志API")
public class JobLogController extends BaseAction {

	@Resource
	private JobLogService jobLogService;

	/**
	 * 查询并分页
	 * @param jobLogForm
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@ApiOperation(value=" 查询并分页", notes=" 查询并分页")
	@GetMapping(value="/list")
	@Auth(value = "/jobLog/list",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public BasePage<List<JobLog>> getJobListByCondition(JobLogForm jobLogForm, Integer pageNo, Integer pageSize){
		commonHPagerByPageNo(pageNo,pageSize);
		List<JobLog> jobLogList = jobLogService.getJobLogListByCondition(jobLogForm);
		PageInfo<JobLog> page = new PageInfo<JobLog>(jobLogList);
		return outPageBootByPageNo(page,pageNo,pageSize);
	}

	/**
	* 查询单个对象
	* @param id
	*/
	@ApiOperation(value=" 查询单个对象", notes=" 查询单个对象")
	@GetMapping(value="/get/{id}")
	@Auth(value = "/jobLog/get",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public BaseResult getJobLogById(@PathVariable("id")String id){
		JobLog jobLog = jobLogService.getJobLogById(id);
		return outDataStr(jobLog);
	}
	
	/**
	* 删除
	* @param id
	*/
	@DeleteMapping(value="/delete")
	@ApiOperation(value=" 删除", notes=" 删除")
	public BaseResult delJobLog(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id",id.split(","));
			i= jobLogService.delJobLog(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 添加
	 * @param jobLog
	 */
	@ApiOperation(value=" 添加", notes=" 添加")
	@PostMapping(value="/add")
	@Auth(value = "/jobLog/add",authenticationType = Auth.AuthorizationType.NOT_REQUIRED_LOGIN)
	public BaseResult addJobLog(@RequestBody JobLog jobLog){
		int i = 0;
		if(null != jobLog){
			i= jobLogService.addJobLog(jobLog);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
}
